<!DOCTYPE html>
<html>
	<head>
		<title>我的游记</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/userTravels.css" />
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<script src="/js/common.js"></script>
		<script>
			$(function () {
                //先拿到存在sessionStorage中的用户数据信息
                var user=JSON.parse(sessionStorage.getItem("user"));
                //定义当前页，用于分页
                var currentPage=1;
                //定义总页数变量
                var pages;
                //定义全局请求状态
                var loading = false;
                //定义变量接收查询数据
                var travelData = [];
                function query() {
                    if(loading) {
                        return;
                    }
                    $.get("/users/" + user.id + "/travels", {currentPage: currentPage}, function (data) {
                        pages=data.pages;
                        //拿到数据，放进容器
                        $.merge(travelData, data.list);
                        //封装容器
                        var json = {list: travelData};
                        //渲染数据
                        $(".travels").renderValues(json,{
                            getHref:getHref
						});
                        loading = false;
                    });
                        currentPage++;
                }

                query();
                //绑定滚动点击事件
                $(window).scroll(function () {
                    //拿到屏高和文档高度,判断划到底发请求第二页数据
                    //0.5可以避免误差问题的重复弹窗提示
                    if ($(window).height() + $(document).scrollTop() + 0.5 >= $(document).height()) {
                        if (currentPage<=pages) {
                            query();
                            loading = true;
                        }else {
                            $(document).dialog({
                                type : 'notice',
                                infoText: '亲，已经到底了，不要再划拉',
                                autoClose: 2500,
                                position: 'bottom'  // center: 居中; bottom: 底部
                            });
                        }
                    }
                });




            });
		</script>
	</head>

	<body>
	<div class="search-head">
		<div class="row nav-search">
			<div class="col">
				<a href="profiles.html">
					<span><i class="fa fa-chevron-left"></i></span>
				</a>
			</div>
			<div class="col">
				<span>我的游记</span>
			</div>
			<div class="col"></div>
		</div>
	</div>


	<div class="container travels">
		<dl class="list" render-loop="list">
        <dd>
			<a render-key="list.id" render-fun="getHref" data-href="/travelContent.html">
				<img render-src="list.coverUrl">
				<h6 class="title" render-html="list.title"></h6>
				<p>最近更新时间 <span render-html="list.lastUpdateTime"></span>
					<span class="span-right">
							  <i class="fa fa-heart"></i><span>0</span>收藏
						  <i class="fa fa-thumbs-o-up"></i><span>0</span>点赞
                    </span>
				</p>
			</a>
		</dd>
		</dl>
	</div>

	</body>
</html>
